package com.gxuwz.service.impl;

import com.gxuwz.dao.ClassesDao;
import com.gxuwz.entity.Classes;
import com.gxuwz.entity.vo.PageVo;
import com.gxuwz.result.PageInfo;
import com.gxuwz.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassesServiceImpl implements ClassesService {

    @Autowired
    private ClassesDao classesDao;

    public PageVo getClassesList(Classes classes, PageInfo pageInfo,String instID) {
        if(classes == null){
            return classesDao.selectClassesAll(null,pageInfo,instID);
        }
        String classID = classes.getClassID();
        String className = classes.getClassName();
        String major = classes.getMajor();
        String grade = classes.getGrade();
        if( (classID!=null && !classID.equals("")) || (className!= null && !className.equals("")) ||
             major!=null && !major.equals("") || grade!=null && !grade.equals("")){
            return classesDao.selectClassesAll(classes, pageInfo,instID);
        } else {
            return classesDao.selectClassesAll(null,pageInfo,instID);
        }
    }

    public Classes getClassesOne(String classId) {
        Classes classes = classesDao.selectClassByID(classId);

        return classes;
    }

    public boolean addClassesInfo(Classes classes) {
        int i = classesDao.insertClass(classes);
        boolean flag = i > 0 ? true : false;
        return flag;
    }

    public boolean updateClassesInfo(Classes classes, String oldId) {
        int i = classesDao.updateClass(classes,oldId);
        boolean flag = i > 0 ? true :false;
        return flag;
    }

    public boolean deleteClassesOne(String classId) {
        int count = classesDao.deleteClassById(classId);
        boolean flag = count > 0 ? true : false;
        return flag;
    }

    public List<String> selectClassesIds() {
        List<String> ids= classesDao.selectClassesIds();
        return ids;
    }

    public List<Classes> queryClassesIdAndClassName(String instID) {
        List<Classes> classesList = classesDao.selectClassesIdsAndName(instID);
        return classesList;
    }

    public List<String> getClassGrades(String instID) {
        List<String> grades = classesDao.selectClassGrades(instID);
        return grades;
    }

    public List<String> getMajors(String instID) {
        List<String> majors = classesDao.selectMajors(instID);
        return majors;
    }

    @Override
    public boolean selectClassesExist(String depId) {
        List<Classes> classesList = classesDao.selectClassesByDepID(depId);
        if(classesList.isEmpty()){
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean selectClassesExistByInstID(String instId) {
        List<Classes> classesList = classesDao.selectClassesByInstID(instId);
        if(classesList.isEmpty()){
            return true;
        } else {
            return false;
        }
    }

    @Override
    public List<String> selectClassesIdsNoDel() {
        List<String> strings = classesDao.selectClassesIdsByNoDel();
        return strings;
    }
}
